package onetomany;

import org.hibernate.Criteria;
import org.hibernate.LockMode;
import org.hibernate.Session;
import org.hibernate.criterion.Restrictions;
import org.junit.Test;

import enity.Classes;
import enity.Student;
import entiy2.Classes3;
import entiy2.Student3;
import entiy3.Employee;
import entiy3.Project;
import mulentiy.Classes2;
import mulentiy.Student2;
import utils.H3Utils;

public class Main {

	
	@Test
	public void test9() {
		Session session = H3Utils.getCurrentSession();
		session.beginTransaction();
		
		session.getTransaction().commit();
		session.close();
	}
	
	@SuppressWarnings("deprecation")
	@Test
	public void test8() {
		Session session = H3Utils.getCurrentSession();
		session.beginTransaction();
		Criteria criteria = session.createCriteria(Project.class);
		criteria.add(Restrictions.eq("PRONAME", "��Ŀ2"));
		//Query query = session.createQuery("from entiy3.Project");
		//query.list();
		session.getTransaction().commit();
		session.close();

	}

	@Test
	public void test6() {
		Session session = H3Utils.getCurrentSession();
		session.beginTransaction();
		Project project = (Project) session.get(Project.class, 1);
		Project project2 = (Project) session.get(Project.class, 3, LockMode.PESSIMISTIC_READ);
		session.delete(project2);
		session.delete(project);
		session.getTransaction().commit();
		session.close();

	}

	@Test
	public void test5() {
		Session session = H3Utils.getCurrentSession();
		session.beginTransaction();
		// ����������Ŀ
		Project pro1 = new Project("��Ŀһ");
		Project pro2 = new Project("��Ŀ��");
		// �������Ա��
		Employee emp1 = new Employee("������꼾");
		Employee emp2 = new Employee("ʢ�ĵĹ�ʵ");
		Employee emp3 = new Employee("����");
		Employee emp4 = new Employee("����ǰ�ĺڰ�");

		pro1.getEmps().add(emp1);
		pro1.getEmps().add(emp2);
		pro1.getEmps().add(emp3);

		pro2.getEmps().add(emp2);
		pro2.getEmps().add(emp3);
		pro2.getEmps().add(emp4);

		session.save(pro1);
		session.save(pro2);
		session.getTransaction().commit();
		session.close();

	}

	@Test
	public void test3() {
		Session session = H3Utils.getCurrentSession();
		session.beginTransaction();
		Classes3 classes3 = new Classes3("����");

		Student3 s2 = new Student3("A");
		Student3 s3 = new Student3("B");

		classes3.getStudents().add(s2);
		classes3.getStudents().add(s3);

		session.save(classes3);
		session.save(s2);
		session.save(s3);
		session.getTransaction().commit();
		session.close();

	}

	@Test
	public void test2() {
		Session session = H3Utils.getCurrentSession();
		session.beginTransaction();
		Classes2 classes2 = new Classes2("����");

		Student2 s2 = new Student2("A");
		Student2 s3 = new Student2("B");

		classes2.setSid(s2);
		classes2.setSid(s3);

		session.save(s2);
		session.save(s3);
		session.save(classes2);
		session.getTransaction().commit();
		session.close();

	}

	@Test
	public void test1() {
		Session session = H3Utils.getCurrentSession();
		session.beginTransaction();
		Classes c = new Classes("����");

		Student s1 = new Student("��̫��");
		Student s2 = new Student("���ʶ�");

		// ���ϣ����ѧ��������Ӷ�Ӧ�İ༶��ţ���Ҫ�ڰ༶�����ѧ��������������ϵ
		c.getStudents().add(s1);

		session.save(c);
		session.save(s1);
		session.getTransaction().commit();
		session.close();

	}

}
